<template>
  <div>
    <el-button type="success" @click.prevent="handleAdd()"
      ><i class="el-icon-circle-plus-outline"></i>新增</el-button
    >

    <el-table
      :data="questionTypeList"
      tooltip-effect="dark"
      style="width: 100%"
    >
      <el-table-column label="编号" prop="id" width="500"> </el-table-column>
      <el-table-column prop="qtname" label="试题类型" width="500">
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleView(scope.row)"
            >详情</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: "QuestionTypeList",
  data() {
    return {
      questionTypeList: [],
      id: 0,
      qtname: null,
    };
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    getList() {
      this.axiosJSON
        .get("/questionType/getAll")
        .then((result) => {
          this.questionTypeList = result.data.data;
        });
    },
    selectSubject(id) {
      //点击TR事件处理
      this.id = id;
      this.$parent.id = id; //辅助给父组件的数据属性
    },
    checkSelected(id) {
      //检查id是否被选中
      return this.id == id;
    },
    // 查看详情
    handleView(row) {
      this.$router.push("/questionType/view/" + row.id);
    },
    // 删除
    handleDelete(row) {
      this.$confirm("确定要删除吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.axiosJSON
            .get("/questionType/delete?id=" + row.id)
            .then((result) => {
              if (result.data.code == 0) {
                this.$message({
                  type: "success",
                  message: result.data.msg,
                });
                //如何刷新子组件的数据,使用事件发送机制
                this.oaevent.$emit("updateSubjectList");
                this.getList();
              } else {
                this.$message.error(result.data.msg);
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    handleAdd() {
      this.$router.push("/questionType/add");
    },
  },
  mounted() {
    this.$parent.questionTypeTitle = "试题类型管理";
    this.$parent.id = 0;
    this.oaevent.$on("updateQuestionTypeList", () => {
      this.getList();
    }); //响应updateSubjectList事件
    this.getList();
  },
};
</script>

<style>
</style>
